package com.shop.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shop.user.po.GoodsComment;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author banxia
 * @since 2023-04-18
 */
public interface GoodsCommentMapper extends BaseMapper<GoodsComment> {

    @Update("update goods_base set comment_count=comment_count+1, comment_score=comment_score+#{rate} where " +
            "id=#{goodsId}")
    public void updateGoodsBaseComment(@Param("goodsId") Long goodsId,
                                       @Param("rate") Long rate);

    @Select("select format(comment_score/comment_count,2) from goods_base where id=#{goodsId}")
    String getrate(@Param("goodsId") Long goodsId);
}
